import httpInstance from "@/utils/http.js";
import {h} from "vue";

/**
 * 根据板块id获取帖子集合
 * @param boardId
 * @param sort
 * @param page
 * @param size
 * @param searchField
 * @returns
 */
export function getArticleListApi(boardId,sort,page,size,searchField){
    return httpInstance.get('/article/list',{
        params:{
            boardId,sort,page,size,searchField
        }
    })
}

/**
 * 根据id获取帖子详情
 * @param articleId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getArticleInfoApi(articleId){
    return httpInstance.get(`/article/${articleId}`)
}

/**
 * 更新帖子点赞、评论数
 * @param articleId
 * @param type 1=点赞，2=评论
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function changeArticleCountApi(articleId,type){
    return httpInstance.post('/article/count',{},{
        params:{
            articleId,type
        }
    })
}

/**
 * 发布文章
 * @param article
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function addArticleApi(article){
    return httpInstance.post('/article/add',{
        ...article
    })
}

/**
 * 获取用户相关的帖子
 * @param userId
 * @param type 类型 0=用户发布的帖子 ，1=用户点赞的帖子，2=用户收藏的帖子
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getUserArticleApi(userId,type){
    return　httpInstance.get(`/article/${userId}/${type}`)
}